<?php

namespace app\mini\controller\v1\client;

use app\common\logic\OrderCommentLogic;
use app\common\model\Content;
use app\mini\controller\Common;
use think\Request;
use think\response\Json;

class Comment extends Common
{

    public $OrderCommentLogic;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->OrderCommentLogic = new OrderCommentLogic();
    }

    /**
     * 商家评价列表
     * @return Json
     */
    public function index(): Json
    {
        $res = $this->exception(function () {
            return $this->OrderCommentLogic->index(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 评论
     * @return Json
     */
    public function comment(): Json
    {
        $res = $this->transException(function () {
            return $this->OrderCommentLogic->comment(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 评论数量统计
     * @return Json
     */
    public function commentCount(): Json
    {
        $res = $this->exception(function () {
            return $this->OrderCommentLogic->commentCount(request()->param());
        });
        return $this->response($res);
    }


    /**
     * 评论内容
     * @return Json
     */
    public function content(): Json
    {
        $res = $this->exception(function () {
            return Content::field('title')->order('id asc')->select()->each(function ($item){
                $item['state'] = false;
                return $item;
            });
        });
        return $this->response($res);
    }
}
